package com.easy.demo.demos.web;

import com.easy.activiti.util.AjaxResponse;
import com.easy.activiti.util.GlobalConfig;
import com.easy.demo.demos.web.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhouchuang
 * @date 2024-11-02 19:52:16
 */

@Controller
public class LoginController {
    private static final Logger log = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private UserService userService;
    @PostMapping("/login")
    @ResponseBody
    public AjaxResponse login(HttpServletRequest request,@RequestParam(name = "username", defaultValue = "unknown user") String username) {
        try {
            userService.login(username);
            return AjaxResponse.AjaxData(GlobalConfig.ResponseCode.SUCCESS.getCode(),
                    GlobalConfig.ResponseCode.SUCCESS.getDesc(), userService.me());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResponse.AjaxData(GlobalConfig.ResponseCode.ERROR.getCode(),
                    "用户登陆失败", e.getMessage());
        }
    }
}
